import React from "react"
import './index.scss'
export default class ToggleBtnGroup extends React.Component{
        constructor (props) {
                super (props);
                this.state={
                        toggleType:this.props.defaultBtnValue
                }
        }
        handleOnClick=value=>{
                const {toggleType} = this.state
                if (toggleType === value) return
                this.setState({toggleType:value},()=>{
                        const {onClick} = this.props
                        if (onClick) onClick(value)
                })
        }
        render () {
                const {toggleType} = this.state
                return <div className='toggle-btn-wrapper'>
                        <div className={`toggle-btn ${toggleType===0&&'active'}`} onClick={this.handleOnClick.bind(this,0)}>供应</div>
                        <div className={`toggle-btn ${toggleType===1&&'active'}`} onClick={this.handleOnClick.bind(this,1)}>内销</div>
                </div>
        }
}
